package com.project.controller;

import com.project.bean.EUserBean;
import com.project.service.IEUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lyl
 * description:
 */
@RestController
@RequestMapping("user")
public class EUserController {
    @Autowired
    private IEUserService ieUserService;

    @RequestMapping("login")
    public String login(HttpServletRequest request, String username, String password) {
        EUserBean e = ieUserService.login(username, password);
        if (e != null) {
            request.getSession().setAttribute("loginUser", e);
            return "ok";
        } else {
            return "no";
        }
    }

    @RequestMapping("getUserSession")
    public EUserBean getUserSession(HttpServletRequest request) {
        return (EUserBean) request.getSession().getAttribute("loginUser");
    }


}
